#pragma once
#include <mutex>
template<typename Tp>
struct _Default_Deleter
{
	inline void operator()(Tp* p) { delete p; }
};

template<typename T, typename _Delete = _Default_Deleter<T> >
class __Singleton__
{
	__Singleton__(const __Singleton__&) = delete;
	__Singleton__& operator= (const __Singleton__&) = delete;
	static std::shared_ptr<T>	_M_data;
	static std::mutex			_M_mutex;
public:

	inline static std::shared_ptr<T> instance()
	{
		if (!_M_data)
		{
			std::lock_guard<std::mutex> _l(_M_mutex);
			if (!_M_data)
			{
				_M_data = std::shared_ptr<T>(new T(), _Delete());
			}
		}
		return _M_data;
	}
};
template<typename T, typename _Delete>
std::shared_ptr<T>	__Singleton__<T, _Delete>::_M_data = nullptr;
template<typename T, typename _Delete>
std::mutex			__Singleton__<T, _Delete>::_M_mutex;